package com.study.dto;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.time.LocalDate;

/**
 * @author zhuzi
 * 2024/3/25 23:49
 */
@Data
@Accessors(chain = true)
public class Student {
    private String name = RandomUtil.randomString(5);
    private LocalDate birth = LocalDate.now().plusDays(RandomUtil.randomInt(1, 5));
    private Long id = IdUtil.getSnowflakeNextId();
    private int age = RandomUtil.randomInt(18, 28);

    @Override
    public boolean equals(Object o) {
        System.out.println("Student.equals");
        if (this == o) return true;
        if (!(o instanceof Student)) return false;
        Student student = (Student) o;
        return new EqualsBuilder().append(name, student.name).isEquals();
    }

    @Override
    public int hashCode() {
        System.out.println("Student.hashCode");
        return new HashCodeBuilder(17, 37).append(name).toHashCode();
    }
}
